class Router {
    /**
     * options: {
     *     path:'/index',
     *     component: Main
     * }
     *
     * 基于js原生的window.addEventListener('load')
     * window.addEventListener('hashchange', function(){}, isScrape)// 是否是在捕获阶段执行
     */
    constructor() {
        this.routes = {}
        this.currentHash = ''
        this.refreshRoute = this.refreshRoute.bind(this)
        this.init()
    }

    init() {
        window.addEventListener('load', this.storeRoute, false)
        window.addEventListener('hashchange', this.refreshRoute, false)
    }

    storeRoute(path, cb) {
        this.routes[path] = cb || function () {}
    }

    refreshRoute() {
        this.currentHash = location.hash.slice(1) || '/'
        this.routes[this.currentHash]()
    }

}


